package com.sunjob.mroresource.util;

import com.sunjob.common.exception.MROException;
import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: TomHuang
 * @date: 2022/8/16 9:15
 */

@Component
public class ResourceUtils {

    //校验工号
    public static void checkJobId(String var){
        String regex = "^[A-Z]{1}[0-9]{5}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher m = pattern.matcher(var);
        if(!m.matches())
            throw new MROException("工号格式不规范",500);
    }

    //校验联系方式
    public static void checkPhone(String var){
        String regex = "^1([3-9][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";
        Pattern pattern = Pattern.compile(regex);
        Matcher m = pattern.matcher(var);
        if(!m.matches())
            throw new MROException("联系方式格式不规范，请输入正确的联系方式",500);
    }

    //校验身份证
    public static void checkIc(String var){
        String regex = "^([1-6][1-9]|50)\\d{4}(18|19|20)\\d{2}((0[1-9])|10|11|12)(([0-2][1-9])|10|20|30|31)\\d{3}[0-9Xx]$";
        Pattern pattern = Pattern.compile(regex);
        Matcher m = pattern.matcher(var);
        if(!m.matches())
            throw new MROException("身份证格式不规范，请输入正确的身份证",500);
    }
    //校验数值范围
    public static void checkRange(int big,int target){
        if(target>big||target<1){
            throw new MROException("您添加的数值超出预设范围，请重新填写",500);
        }
    }
}
